/**
 * 文件：EditLocationTextBox.java
 * 包名：com.ronri.list.editview.controls;   --- 正式发布时需要修正
 * 说明：定位信息编辑
 * 作者：MS During
 * 日期：2017/5/4
 * 历史：
 */
package com.ronri.list.editview.controls;

import android.view.View;
import android.widget.EditText;
import android.widget.PopupWindow;

import com.cz.nongyetongv5.R;


public class EditLocationTextBox extends EditTextBox {

    // 值
    private String mValidate= "";

    // 弹框
    PopupWindow popupWindow = null;

    // 编辑框
    // EditText editText = null;

    View view = null;

    /***
     * 构造函数
     */
    public EditLocationTextBox() {
        super();
        this.ControlName = "EditLocationTextBox";
        this.BindLayout(R.layout.control_location_textbox);
    }

    /***
     * 装载控件
     * @return
     */
    @Override
    public boolean LoadEditControl() {
        return super.LoadEditControl();
    }

    /***
     * 显示控件
     * @return
     */
    @Override
    public boolean ShowEditControl(View Anchor) {
        //Intent intent = new Intent(getApplication(), activity_sample_list.class);
        // startActivity(intent);
//
//        WindowManager manager = (WindowManager) SystemApplication.getInstance().getSystemService(Context.WINDOW_SERVICE);
//        @SuppressWarnings("deprecation")
//        int nWidth = manager.getDefaultDisplay().getWidth();
//        int nHeight = manager.getDefaultDisplay().getHeight();
//
//        view = getView();
//        view.setSaveEnabled(false);
//
//        ImageView imgViewCancel = (ImageView) view.findViewById(R.id.edit_fail);
//        TextView imgViewOK = (TextView)view.findViewById(R.id.edit_success);
//        TextView textView = (TextView)view.findViewById(R.id.controlEdit);
//        Button btVoice = (Button)view.findViewById(R.id.buttonGetVoice);
//        Button btLocation = (Button)view.findViewById(R.id.buttonGetLocation);
//
//        EditText eText =(EditText)view.findViewById(R.id.controlEdit);
//        eText.requestFocus();
//
//        // 绑定编辑视图
//        // this.bindEditView(editText);
//
//        imgViewCancel.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                popupWindow.dismiss();
//            }
//        });
//
//        /***
//         * 确认返回结果集
//         */
//        imgViewOK.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//
//                if(BaseControlEevnt != null){
//
//                    // 校验数据
//                    boolean bRet = Validate();
//
//                    // 回调，传递结果
//                    BaseControlEevnt.ReturnValue(this);
//                }
//
//                popupWindow.dismiss();
//            }
//        });
//
//        btLocation.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                getLoacteAddressText();
//            }
//        });
//
//        btVoice.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                getVoiceText();
//            }
//        });
//
//        popupWindow = new PopupWindow(view,
//                WindowManager.LayoutParams.MATCH_PARENT,
//                nHeight - SystemManager.getStatusBarHeight(), true);
//
//        textView.setOnKeyListener(new View.OnKeyListener() {
//            @Override
//            public boolean onKey(View v, int keyCode, KeyEvent event) {
//
//                if(event.getAction() == KeyEvent.ACTION_DOWN && keyCode == KeyEvent.KEYCODE_BACK)
//                    popupWindow.dismiss();
//
//                return false;
//            }
//        });
//
//        // 设置弹出窗体显示时的动画，从底部向上弹出
//        popupWindow.setAnimationStyle(R.style.take_photo_anim);
//        popupWindow.showAtLocation(Anchor, Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL, 0, 0);

        return super.ShowEditControl(Anchor);
    }

    /***
     * 隐藏控件
     * @return
     */
    @Override
    public boolean HideEditControl() {
        return super.HideEditControl();
    }

    /****
     * 身份证验证
     * @return
     */
    @Override
    public boolean Validate() {

        EditText ctl = (EditText)this.getView();

        String szValue = ctl.getText().toString();

        if (szValue.length() == 13)
            return true;

        return false;
    }

    @Override
    public String toString() {
        return "adfasdfasd";
    }

    /***
     * 获取错误信息
     * @return
     */
    @Override
    public String GetErrorMessage() {
        return getContext().getString(R.string.validate_card_error);
    }

    /***
     * 回调返回结果
     * @param szString
     */
    @Override
    public void CallBackResult(String szString) {
        super.CallBackResult(szString);
        EditText editText = (EditText) popupWindow.getContentView().findViewById(R.id.controlEdit);
        editText.setText(szString);
    }
}
